<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.4/lib/index.css">

  <link rel="stylesheet" href="/css/global.css">
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vant@2.4/lib/vant.min.js"></script>
  <!--    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
  <script src="https://cdn.bootcss.com/qs/6.5.2/qs.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
</head>
<body>
<!--<p>当前时间：${.now?string("yyyy-MM-dd HH:mm:ss.sss")}</p>-->
<div class="bg"></div>
<div id="app">
  <van-row>
    <van-col span="24">
      <div class="box m-4 p-3">
        <div class="d-flex align-items-center">
          <div>
            <van-image
              round
              width="40"
              height="40"
              src="https://img.yzcdn.cn/vant/cat.jpeg"
            />
          </div>
          <p class="pl-3">aaa</p>
        </div>
      </div>
    </van-col>
  </van-row>
  <van-row class="text-center pl-4 pr-4" gutter="20">
    <van-col span="12">
      <div class="box p-3">
        <p class="color-main size4">{{msgdata.NewWeight}}</p>
        <p class="size1 color-ash">当前公斤</p>
      </div>
    </van-col>
    <van-col span="12">
      <div class="box p-3">
        <p class="color-main size4">{{msgdata.TargetWeight}}</p>
        <p class="size1 color-ash">目标公斤</p>
      </div>
    </van-col>
  </van-row>
  <van-row>
    <van-col span="24">
      <div class="box p-3 m-4 text-center d-flex align-items-center" style="justify-content: space-evenly">
        <div>
          <p class="size1 color-ash">摄入</p>
          <p class="size4 bold">{{msgdata.take}}</p>
        </div>
        <van-circle v-model="currentRate" :rate="70" :speed="100" size="150px" :color="gradientColor">
          <div class="d-flex align-items-center justify-content-center h-100">
            <div>
              <p class="size1 color-ash">还可以吃</p>
              <p class="size6 bold">{{msgdata.EatCalories}}</p>
              <p class="size1 color-ash">推荐预算{{msgdata.regular}}</p>
            </div>
          </div>
        </van-circle>
        <div>
          <p class="size1 color-ash">运动</p>
          <p class="size4 bold">{{msgdata.cosume}}</p>
        </div>
      </div>
    </van-col>
    <van-col span="24">
      <div class="box ml-4 mr-4 p-3">
        <div class="d-flex justify-content-between pb-3 border-bottom">
          <span>你今天的饮食</span>
          <span class="color-lesser">总共{{msgdata.take}}千卡</span>
        </div>
        <ul class="breakfast-list">
          <p v-show="foodNullSign">你今天还没吃饭呢！</p>
          <li v-for="(mm,index) in msgdata.fin" v-show="foodListSign">
            <div class="flex-grow-shrink">
              <!--                            <van-image-->
              <!--                                    width="80px"-->
              <!--                                    height="80px"-->
              <!--                                    fit="cover"-->
              <!--                                    src="https://img.yzcdn.cn/vant/cat.jpeg"-->
              <!--                            />-->
              <img :src="mm.imgurl" width="80px" height="80px"/>
            </div>
            <div class="w-100 pl-3 pr-3">
              <p class="size3 bold">{{mm.name}}x{{mm.quanity}}</p>
              <p class="size1 color-ash mt-2">{{mm.createtime}}</p>
            </div>
            <span class="flex-grow-shrink color-lesser">{{mm.calories}}千卡</span>
            <van-icon name="../image/delete.png" size="40" @click="deleteFood(index)"></van-icon>
          </li>

        </ul>
        </br>
        </br>
        </br>
        </br>
        <div class="d-flex justify-content-between pb-3 border-bottom">

          <span>你今天的运动</span>
          <span class="color-lesser">总共{{msgdata.cosume}}千卡</span>
        </div>
        <ul class="breakfast-list">
          <p v-show="movNullSign">宁今天动都没动，减**的肥</p>
          <li v-for="(mm,index) in msgdata.ein" v-show="movListSign">
            <div class="flex-grow-shrink">
              <!--                            <van-image-->
              <!--                                    width="80px"-->
              <!--                                    height="80px"-->
              <!--                                    fit="cover"-->
              <!--                                    src="https://img.yzcdn.cn/vant/cat.jpeg"-->
              <!--                            />-->
              <img :src="mm.imgurl" width="80px" height="80px"/>
            </div>
            <div class="w-100 pl-3 pr-3">
              <p class="size3 bold">{{mm.name}}x{{mm.quanity}}</p>
              <p class="size1 color-ash mt-2">{{mm.createtime}}</p>
            </div>
            <span class="flex-grow-shrink color-lesser">总共{{mm.calories}}千卡</span>
            <van-icon name="../image/delete.png" size="40" @click="deleteMov(index)"></van-icon>
          </li>

        </ul>
      </div>
    </van-col>
  </van-row>
  <!--    <van-tabbar v-model="active">-->
  <!--        <van-tabbar-item icon="home-o">标签</van-tabbar-item>-->
  <!--        <van-tabbar-item icon="search">标签</van-tabbar-item>-->
  <!--        <van-tabbar-item icon="friends-o">标签</van-tabbar-item>-->
  <!--        <van-tabbar-item icon="setting-o">标签</van-tabbar-item>-->
  <!--    </van-tabbar>-->
  <van-row class="text-center pl-4 pr-4" gutter="20">
    <van-grid :column-num="3" class="index-grid-item">
      <van-grid-item icon="../image/eat.png" text="饮食" @click="toLookforfood"></van-grid-item>
      <van-grid-item icon="../image/icon2.png" text="运动" @click="toLookforMov"></van-grid-item>
      <van-grid-item icon="../image/weight_scale.png" text="记录体重"></van-grid-item>
    </van-grid>
  </van-row>
  <van-row>

    <van-col span="24">
      <div style="height: 80px;"></div>
      <div class="fixed-bottom p-2 bg-white" style="box-sizing: border-box">
        <van-button square color="linear-gradient(to right, #4bb0ff, #6149f6)" block @click="toPersonalCenter">个人中心
        </van-button>
      </div>
    </van-col>
  </van-row>
</div>
</body>
<script>
  var vm = new Vue({
    el: '#app',
    data() {
      return {
        msgdata: {
          take: '',
          EatCalories: '',
          NewWeight: '',
          TargetWeight: '',
          cosume: '',
          regular: '',
          fin: [
            {
              calories: '',
              createtime: '',
              fmId: '',
              id: '',
              name: '',
              quanity: '',
              type: '',
              unitid: '',
              userId: '',
              imgurl: '',
            },
          ],
          ein: [
            {
              calories: '',
              createtime: '',
              id: '',
              mmid: '',
              name: '',
              quanity: '',
              type: '',
              userid: '',
              imgurl: '',
            },
          ],
        },
        foodListSign: true,
        foodNullSign: false,
        movListSign: true,
        movNullSign: false,
        currentRate: 0,
        gridvalue: '',
        gradientColor: {
          '0%': '#3fecff',
          '100%': '#6149f6',
        },
      };
    },
    mounted: function () {
      axios.post(`/personUser/getRecord`)
        .then(res = > {
        console.log("res is=>", res.data);
      console.log("res is=>", res.data.toString());
      vm.$data.msgdata.take = res.data.take;
      vm.$data.msgdata.EatCalories = res.data.EatCalories;
      vm.$data.msgdata.NewWeight = res.data.NewWeight;
      vm.$data.msgdata.TargetWeight = res.data.TargetWeight;
      vm.$data.msgdata.cosume = res.data.cosume;
      vm.$data.msgdata.regular = res.data.regular;
      vm.$data.msgdata.fin = res.data.fin;
      vm.$data.msgdata.ein = res.data.ein;
      if (res.data.fin == null || vm.$data.msgdata.fin == "") {
        foodListSign = false;
        foodNullSign = true;
      } else {
        foodListSign = true;
        foodNullSign = false;

        //将图片地址都拼接上require
        for (var i = 0; i < vm.$data.msgdata.fin.length; i++) {
          vm.$data.msgdata.fin[i].imgurl = "../image/userImg/" + vm.$data.msgdata.fin[i].imgurl;
          console.log("this new img " + vm.$data.msgdata.fin[i].imgurl);
        }
      }
      if (res.data.ein == null || vm.$data.msgdata.ein == "") {
        movListSign = false;
        movNullSign = true;

      } else {
        movNullSign = false;
        movListSign = true;

        for (var j = 0; j < vm.$data.msgdata.ein.length; j++) {
          vm.$data.msgdata.ein[j].imgurl = "../image/userImg/" + vm.$data.msgdata.ein[j].imgurl;
          console.log("this eee new img " + vm.$data.msgdata.ein[j].imgurl);
        }
      }


      // console.log(vm.$data.ModelUnitAndIfo);


      if (res.data.returnMsg != null)
        alert(res.data.returnMsg.toString());
    }
    )
    },
    methods: {
      onClickLeft() {
        Toast('返回');
      },
      toPersonalCenter() {
        window.location.href = "toPersonalCenter";
      },
      toLookforfood() {
        window.location.href = "toLookforfood";
      },
      toLookforMov() {
        window.location.href = "tolookformov";
      },
      deleteMov(index) {
        let postdata = {
          movInstanceId: vm.$data.msgdata.ein[index].id,

        };
        console.log("this id is" + postdata.movInstanceId);
        axios.post(`/movuser/deleteMovInstance`, Qs.stringify(postdata))
          .then(res = > {
          console.log("res is=>", res.data);
        console.log("res is=>", res.data.toString());
        // console.log(vm.$data.ModelUnitAndIfo);
        if (res.data.returnMsg != null) {
          alert(res.data.returnMsg.toString());
          if (res.data.returnMsg == "删除成功") {
            vm.$data.msgdata.ein.splice(index, 1)
          }
        }
        ;

      }
      )
      },
      deleteFood(index) {
        let postdata = {
          FoodInstanseId: vm.$data.msgdata.fin[index].id,
        };
        axios.post(`/fooduser/deleteFoodInstanse`, Qs.stringify(postdata))
          .then(res = > {
          console.log("res is=>", res.data);
        console.log("res is=>", res.data.toString());
        // console.log(vm.$data.ModelUnitAndIfo);
        if (res.data.returnMsg != null) {
          alert(res.data.returnMsg.toString());
          if (res.data.returnMsg == "你成功把食物吐出来了，我就当你没吃过！") {
            vm.$data.msgdata.fin.splice(index, 1)
          }
        }
      }
      )
      }
    },
    computed: {
      text() {
        return this.currentRate.toFixed(0) + '%';
      },
    },
  });
</script>
</html>
